﻿#region License
/*
 *CopyRight (c) By Denuvead All Rights Reserved
 *CreateDate:
 *Info:
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;
using PriErp.Data;
using PriErp.Tools.Extensions;

namespace PriErp.Dal
{
	public class TransCategory
	{
		#region Model
		/// <summary>
		/// 分类ID
		/// </summary>
		public int CategoryID { get; set; }
		/// <summary>
		/// 分类名称
		/// </summary>
		public string TypeName { get; set; }
		#endregion Model
	}
	/// <summary>
	/// 交易分类业务操作
	/// </summary>
	public static class TransCategoryDAL
	{
		#region  BasicMethod
		/// <summary>
		/// 增加分类
		/// </summary>
		/// <param name="model">插入的分类</param>
		/// <returns>是否成功增加</returns>
		public static bool Add(TransCategory model)
		{
			string strSql = @"insert into TransCategories(Type) values (@Type)";
			SQLiteParameter[] parameters = {
					DbHelperSQLite.MakeParams("@TypeName", DbType.String,20,model.TypeName)};
			return DbHelperSQLite.ExecuteSql(strSql, parameters) > 0;
		}

		/// <summary>
		/// 更新分类
		/// </summary>
		/// <param name="model">修改的分类</param>
		/// <returns>返回是否成功修改</returns>
		public static bool Update(TransCategory model)
		{
			string strSql = "update TransCategories set TypeName=@TypeName where CategoryID=@CategoryID";
			SQLiteParameter[] parameters = {
					DbHelperSQLite.MakeParams("@TypeName", DbType.String,20,model.TypeName),
					new SQLiteParameter("@CategoryID", model.CategoryID)};
			return DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters) > 0;
		}

		/// <summary>
		/// 删除记录
		/// </summary>
		/// <param name="Ids">需要删除的分类ID</param>
		/// <returns>是否删除成功</returns>
		public static bool Delete(List<int> Ids)
		{
			string strSql = string.Format("delete from TransCategories where CategoryID in({0})", Ids.ToUninString(','));
			return DbHelperSQLite.ExecuteSql(strSql) > 0;
		}
		#endregion  BasicMethod
	}
}
